package org.wen.soft.generate.util;

import org.wen.soft.asm.model.LoadParameter;

import java.util.ArrayList;
import java.util.List;

public class ParameterUtil {


    /**
     * todo 需要考虑使用局部变量
     * any(String.class), any(List.class)
     */
    public static String parameterMockStr(List<String> classNames) {
        List<String> mocks = new ArrayList<>();
        for (String className : classNames) {
            mocks.add(MappingUtil.mappingMockValue(className));
        }
        return String.join(", ", mocks);
    }

    /**
     * String name, List<String> list
     */
    public static String parameterDefStr(List<String> simpleNames, List<LoadParameter> loadParameters) {
        boolean isMappingParam = loadParameters != null && loadParameters.size() == simpleNames.size();
        List<String> defs = new ArrayList<>();
        for (int i = 0; i < simpleNames.size(); i++) {
            String simpleName = simpleNames.get(i);
            String paramName = "var" + i;
            if (isMappingParam) {
                paramName = loadParameters.get(i).getName();
            }
            defs.add(simpleName + " " + paramName);
        }
        return String.join(", ", defs);
    }

    /**
     * String.class, List.class
     */
    public static String parameterClassStr(List<String> classNames) {
        List<String> classes = new ArrayList<>();
        for (String className : classNames) {
            classes.add(GStrUtil.simpleName(className) + ".class");
        }
        return String.join(", ", classes);
    }

    /**
     * parameterValueStr
     */
    public static String parameterValueStr(List<String> classNames){
        List<String> values = new ArrayList<>();
        for (String className : classNames) {
            values.add(MappingUtil.mappingValue(className));
        }
        return String.join(", ", values);
    }
}
